/*
 * This file Copyright (c) 2015. Walle.
 * (http://www.wallellen.com). All rights reserved.
 *
 *
 * This file is dual-licensed under both the
 * Walle Agreement (WA) and the GNU General Public License.
 * You may elect to use one or the other of these licenses.
 *
 * This file is distributed in the hope that it will be
 * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
 * Redistribution, except as permitted by whichever of the GPL
 * or WA you select, is prohibited.
 *
 * 1. For the GPL license (GPL), you can redistribute and/or
 * modify this file under the terms of the GNU General
 * Public License, Version 3, as published by the Free Software
 * Foundation.  You should have received a copy of the GNU
 * General Public License, Version 3 along with this program;
 * if not, write to the Free Software Foundation, Inc., 51
 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * 2. For the Walle Agreement (WA), this file
 * and the accompanying materials are made available under the
 * terms of the WA which accompanies this distribution, and
 * is available at http://www.wallellen.com/agreement.html
 *
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
 */

package com.wallellen.knowledge.doc.domain;

import org.hibernate.annotations.GenericGenerator;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

@Entity(name = "FarmDocfile")
@Table(name = "farm_docfile")
public class Docfile implements java.io.Serializable {
    private static final long serialVersionUID = 3911185369411888075L;

    @Id
    @GenericGenerator(name = "systemUUID", strategy = "uuid")
    @GeneratedValue(generator = "systemUUID")
    @Column(name = "ID", length = 32, insertable = true, updatable = true, nullable = false)
    private String id;
    @Column(name = "PSTATE", length = 2, nullable = false)
    private String pstate;
    @Column(name = "EUSER", length = 32, nullable = false)
    private String euser;
    @Column(name = "PCONTENT", length = 128)
    private String pcontent;
    @Column(name = "EUSERNAME", length = 64, nullable = false)
    private String eusername;
    @Column(name = "CUSER", length = 32, nullable = false)
    private String cuser;
    @Column(name = "CUSERNAME", length = 64, nullable = false)
    private String cusername;
    @Column(name = "ETIME", length = 16, nullable = false)
    private String etime;
    @Column(name = "CTIME", length = 16, nullable = false)
    private String ctime;
    @Column(name = "FILENAME", length = 64, nullable = false)
    private String filename;
    @Column(name = "DIR", length = 256, nullable = false)
    private String dir;
    @Column(name = "LEN", length = 12, nullable = false)
    private Float len;
    @Column(name = "EXNAME", length = 16, nullable = false)
    private String exname;
    @Column(name = "NAME", length = 64, nullable = false)
    private String name;
    @Column(name = "TYPE", length = 2, nullable = false)
    private String type;
    @Column(name = "SERVERID", length = 32, nullable = false)
    private String serverid;

    @Transient
    private File file;
    @Transient
    private String url;

    public Docfile() {
    }

    public Docfile(String dir, String serverid, String type, String name,
                   String filename, String ctime, String etime, String cusername,
                   String cuser, String eusername, String euser, String pstate) {
        this.dir = dir;
        this.serverid = serverid;
        this.type = type;
        this.name = name;
        this.filename = filename;
        this.ctime = ctime;
        this.etime = etime;
        this.cusername = cusername;
        this.cuser = cuser;
        this.eusername = eusername;
        this.euser = euser;
        this.pstate = pstate;
    }

    public Docfile(String dir, String serverid, String type, String name,
                   String filename, String ctime, String etime, String cusername,
                   String cuser, String eusername, String euser, String pstate,
                   String pcontent, String exname, Float len) {
        this.dir = dir;
        this.serverid = serverid;
        this.type = type;
        this.name = name;
        this.filename = filename;
        this.ctime = ctime;
        this.etime = etime;
        this.cusername = cusername;
        this.cuser = cuser;
        this.eusername = eusername;
        this.euser = euser;
        this.pstate = pstate;
        this.exname = exname;
        this.len = len;
        this.pcontent = pcontent;
    }

    public String getPstate() {
        return this.pstate;
    }

    public void setPstate(String pstate) {
        this.pstate = pstate;
    }

    public String getEuser() {
        return this.euser;
    }

    public void setEuser(String euser) {
        this.euser = euser;
    }

    public String getPcontent() {
        return this.pcontent;
    }

    public void setPcontent(String pcontent) {
        this.pcontent = pcontent;
    }

    public String getEusername() {
        return this.eusername;
    }

    public void setEusername(String eusername) {
        this.eusername = eusername;
    }

    public String getCuser() {
        return this.cuser;
    }

    public void setCuser(String cuser) {
        this.cuser = cuser;
    }

    public String getCusername() {
        return this.cusername;
    }

    public void setCusername(String cusername) {
        this.cusername = cusername;
    }

    public String getEtime() {
        return this.etime;
    }

    public void setEtime(String etime) {
        this.etime = etime;
    }

    public String getCtime() {
        return this.ctime;
    }

    public void setCtime(String ctime) {
        this.ctime = ctime;
    }

    public String getId() {
        return this.id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getFilename() {
        return this.filename;
    }

    public void setFilename(String filename) {
        this.filename = filename;
    }

    public String getDir() {
        return this.dir;
    }

    public void setDir(String dir) {
        this.dir = dir;
    }

    public Float getLen() {
        return len;
    }

    public void setLen(Float len) {
        this.len = len;
    }

    public String getExname() {
        return this.exname;
    }

    public void setExname(String exname) {
        this.exname = exname;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getType() {
        return this.type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getServerid() {
        return this.serverid;
    }

    public void setServerid(String serverid) {
        this.serverid = serverid;
    }

    public InputStream getInputStream() throws FileNotFoundException {
        return new FileInputStream(file);
    }

    public File getFile() {
        return file;
    }

    public void setFile(File file) {
        this.file = file;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

}